package com.zj.project.common.utils

import androidx.appcompat.app.AppCompatActivity
import java.util.*

/**
 *
 * @ClassName:      ActivityUtils
 * @Author:         Lau
 * @CreateDate:     2021/6/29 11:23
 * @Description:
 */
object ActivityUtils {
    private var stack: Stack<AppCompatActivity> = Stack()

    fun pushActivity(activity: AppCompatActivity?) {
        stack.push(activity)
    }

    fun pop() {
        if (stack.isEmpty()) {
            return
        }
        stack.pop()
    }

    fun popFinish() {
        if (stack.isEmpty()) {
            return
        }
        stack.pop().finish()
    }

    fun currentActivity(): AppCompatActivity? {
        return if (stack.isEmpty()) {
            null
        } else stack.peek()
    }


    fun popAll() {
        for (a in stack) {
            a.finish()
        }
    }
}